﻿using System.Linq;

namespace XEvolve.Core.Runtime
{
    public abstract class Plugin
    {
        private readonly Plugin[] dependencies;

        private bool IsInstalled { get; set; }

        protected Plugin() : this(new Plugin[0])
        {
        }

        protected Plugin(Plugin[] dependencies)
        {
            this.dependencies = dependencies;
            IsInstalled = false;
        }

        internal void Install(Platform platform)
        {
            if (IsInstalled) return;
            foreach (var plugin in dependencies.Where(dependency => !dependency.IsInstalled))
            {
                plugin.Install(platform);
            }
            Initialize(platform);
            IsInstalled = true;
        }

        protected abstract void Initialize(Platform platform);
    }
}